/**
 * 分页结果封装
 */
class PageResult {

    constructor(pageNo, pageSize) {
        this.pageSize = parseInt(pageSize);
        this.pageNo = parseInt(pageNo);
        this.offset = (this.pageNo - 1) * this.pageSize
    }

    init(total, data, url) {
        this.total = parseInt(total);
        this.url = url;
        this.data = data;
        this.totalPage = this.total % this.pageSize > 0 ? Math.floor(this.total / this.pageSize) + 1 : Math.floor(this.total / this.pageSize);
        this.nextUrl = this.pageNo < this.totalPage ? `${this.url}/${(this.pageNo + 1)}?pageSize=${this.pageSize}` : `${this.url}/${this.totalPage}?pageSize=${this.pageSize}`;
        this.prevUrl = this.pageNo <= 1 ? `${this.url}/1?pageSize=${this.pageSize}` : `${this.url}/${this.pageNo - 1}?pageSize=${this.pageSize}`;
    }
}
module.exports = PageResult;